package com.study.controller;

import com.mysql.cj.util.StringUtils;
import com.study.model.MsgCode;
import com.study.service.MsgCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @desc:
 * @author: panxiyi
 * @date: 2023/5/3 11:43 下午
 */

@RestController
@RequestMapping("/msg_code")
public class MsgCodeController {

    @Autowired
    private MsgCodeService msgCodeService;

    // 生成验证码
    @RequestMapping(value = "/code_gen", method = RequestMethod.GET)
    public String generateCode(String tele) {
        return msgCodeService.genCode(tele);
    }

    // 校验验证码
    @RequestMapping(value = "/code_check", method = RequestMethod.POST)
    public Boolean checkCode(MsgCode msgCode) {
        if (msgCode == null || StringUtils.isNullOrEmpty(msgCode.getCode()) || StringUtils.isNullOrEmpty(msgCode.getTele())) {
            return false;
        }
        return msgCodeService.checkCode(msgCode);
    }

}
